﻿<?php
function DoCommandSysLog($command_type)
{
	switch ($command_type) {
		case "select_log_error":
			HttpAction_GetLogErrorInfo();	//查询某条错误信息
			break;
			
		case "total_query_user_count":
			HttpAction_QueryUserCount();	//查询用户总数
			break;
		case "total_query_user_count_login_month":
			HttpAction_QueryUserCountLoginMonth();	//查询用户月登陆总数
			break;
			
		default:
			break;
	}
}
 
function DoCommandPagindSysLog($command_type)
{
	switch ($command_type) {
		case "get_log_error_total": 
			HttpAction_GetLogErrorTotal();	//获取错误信息总数
			break; 
		case "get_log_error_list": 
			HttpAction_GetLogErrorlList();	//查询错误信息
			break; 
			
		case "get_sys_log_basic_list": 
			HttpAction_GetSysLogBasicList();	//查询记录基础信息
			break;  
			
		case "get_sys_log_basic_attribute_list": 
			HttpAction_GetSysLogBasicAttributeList(); //查询属性信息
			break;  
			
		case "get_sys_log_total_list": 
			HttpAction_GetSysLogTotalList();	//查询操作数值信息
			break;  
			
		default:
			break;
	}
} 

#-错误信息总数
function HttpAction_GetLogErrorTotal()
{	
	$str_sql = sprintf("select count(*) as total_count from t_log_error");
	DBHelper::QueryReturnJSON($str_sql);
}

//错误信息查询
function HttpAction_GetLogErrorlList()
{
	$page_index = GetRequest("page_index"); //当前查询的页码
	$per_page_count = GetRequest("per_page_count"); //每页行数
	$count = ($page_index - 1) * $per_page_count;

	$str_sql = sprintf("select * from t_log_error ");
	$str_sql = sprintf("%s limit %d, %d", $str_sql, $count, $per_page_count);

	DBHelper::QueryReturnJSON($str_sql);
}

//--查询错误信息
function HttpAction_GetLogErrorInfo()
{
	$id = GetRequest("id"); //当前查询的页码
	$str_sql = sprintf("select * from t_log_error where id=%d", $id);

	DBHelper::QueryReturnJSON($str_sql);
}

//--查询用户总数
function HttpAction_QueryUserCount()
{
	$str_sql = sprintf("select count(uid) as total_user_count from t_user;");

	DBHelper::QueryReturnJSON($str_sql);
}

//查询用户月登陆总数
function HttpAction_QueryUserCountLoginMonth()
{
	$year_month = GetRequest("year_month"); 
	$str_sql = "select count(distinct(uid)) as total_user_count_login from t_log_login where DATE_FORMAT(s_time, '%Y-%m') = '". $year_month . "'";

	DBHelper::QueryReturnJSON($str_sql);
}

//查询记录基础信息
function HttpAction_GetSysLogBasicList()
{
	$datetime_begin = GetRequest("datetime_begin"); 
	$datetime_end = GetRequest("datetime_end"); 

	if(JudgeDateTime($datetime_begin, $datetime_end) == 1)
	{
		ReturnJSONErrorMsg("参数错误: 开始时间>结束时间");
		return;
	}

	//--获取日期成数组
	$tmpDatetimeArray = GetDataArrayFromBeginToEnd($datetime_begin, $datetime_end);
 
	$msg = "";
	$returnArray = array(); 
	
	//---根据日期数组查询相应的信息
	foreach($tmpDatetimeArray as $tmpVal)
	{  		
		$datetime = $tmpVal;  		//日期
		$day_login = 0;  			//日登录
		$day_login_distinct = 0;  	//日登录(去掉重复UID)
		
		$day_login_sumtime = 0; 	//日在线总时长
		$day_login_sumtime_avg = 0; //日平均在线
		
		$day_reg = 0;  				//日新增注册人数
		
		$day_online_heigh = 0;  	//日最高在线人数
		$day_online_low = 0;  		//日最低在线人数
		$day_online_average = 0;  	//日平均在线人数
			
		$tmpItem = array();
		$tmpItem["datetime"] = $tmpVal;
				
		//日登录, 日平均在线时长
		$sql = "select count(uid) as total_count, count(distinct(uid)) as total_count_distinct, sum(sumtime) as total_sumtime from t_log_login where date_format(s_time, '%Y-%m-%d') = date_format('$tmpVal', '%Y-%m-%d')";
		$rArray = DBHelper::Query($sql, $msg); 
		if($rArray != -1 && count($rArray) >0 )
		{
			$day_login= $rArray[0]["total_count"]; 						//日登陆
			$day_login_distinct = $rArray[0]["total_count_distinct"]; 	//日登陆(去掉重复UID)
			$day_login_sumtime = $rArray[0]["total_sumtime"];			//在线总时长(秒)
		}
		$tmpItem["day_login"] = $day_login; 						//日登陆
		$tmpItem["day_login_distinct"] = $day_login_distinct; 		//日登陆(去掉重复UID)
		
		$tmpItem["day_login_sumtime"] = $day_login_sumtime; 		//日在线总时长(秒)
		if($day_login < 1)
			$day_login = 1;
		$day_login_sumtime_avg = GetFloatFormat($day_login_sumtime / $day_login); 	//日平均在线(秒)
		$tmpItem["day_login_sumtime_avg"] = $day_login_sumtime_avg;
			
		//日新增注册
		$sql = "select count(uid) as total_count from t_user where date_format(regtime, '%Y-%m-%d') = date_format('$tmpVal', '%Y-%m-%d')";
		$rArray = DBHelper::Query($sql, $msg); 
		if($rArray != -1 && count($rArray) >0 )
		{
			$day_reg = $rArray[0]["total_count"]; 
		}			
		$tmpItem["day_reg"] = $day_reg; 
			 
		//日在线人数
		$sql = "select max(count) as max_count, min(count) as min_count, avg(count) as average_count from t_log_online where date_format(timeline, '%Y-%m-%d')  = date_format('$tmpVal', '%Y-%m-%d')";
		$rArray = DBHelper::Query($sql, $msg); 
		if($rArray != -1 && count($rArray) >0 )
		{
			$day_online_heigh = $rArray[0]["max_count"];  
			$day_online_low = $rArray[0]["min_count"];  
			$day_online_average = GetFloatFormat($rArray[0]["average_count"]);  //获取小数点后两位
			
		}
		$tmpItem["day_online_heigh"] = $day_online_heigh;  
		$tmpItem["day_online_low"] = $day_online_low;  
		$tmpItem["day_online_average"] = $day_online_average; 
		
		$returnArray[] = $tmpItem;	 
	}	
	ReturnJSONFromResultArray($returnArray, "", "");
}


//查询属性信息
function HttpAction_GetSysLogBasicAttributeList()
{
	$datetime_begin = GetRequest("datetime_begin"); 
	$datetime_end = GetRequest("datetime_end"); 

	if(JudgeDateTime($datetime_begin, $datetime_end) == 1)
	{
		ReturnJSONErrorMsg("参数错误: 开始时间>结束时间");
		return;
	}

	//--获取日期成数组
	$tmpDatetimeArray = GetDataArrayFromBeginToEnd($datetime_begin, $datetime_end);
 
	$msg = "";
	$returnArray = array(); 
	
	//---根据日期数组查询相应的信息
	foreach($tmpDatetimeArray as $tmpVal)
	{  		
		$datetime = $tmpVal;  		//日期
		
		$day_gold_sys_provide = 0;	//日发放金币数
		$day_gold_use = 0;	  		//日消耗金币数
		$day_money_sys_provide = 0;	//日发放比索数
		$day_money_use = 0;	  		//日消耗比索数
			
		$tmpItem = array();
		$tmpItem["datetime"] = $tmpVal;
				 
		$sql = "select * from t_log_total_everyday where date_format(s_time, '%Y-%m-%d') = date_format('$tmpVal', '%Y-%m-%d')";
  
		$rArray = DBHelper::Query($sql, $msg); 
		if($rArray != -1 && count($rArray) >0 )
		{
			$day_gold_sys_provide= $rArray[0]["gold_sys_provide"]; 		//日发放金币数
			$day_gold_use = $rArray[0]["gold_use"]; 					//日消耗金币数
			$day_money_sys_provide= $rArray[0]["money_pay"]; 		//日发放比索数
			$day_money_use = $rArray[0]["money_use"]; 					//日消耗比索数
		}
		$tmpItem["day_gold_sys_provide"] = $day_gold_sys_provide; 		//日发放金币数
		$tmpItem["day_gold_use"] = $day_gold_use; 						//日消耗金币数
		$tmpItem["day_money_sys_provide"] = $day_money_sys_provide; 		//日发放比索数
		$tmpItem["day_money_use"] = $day_money_use; 						//日消耗比索数
		 
		$returnArray[] = $tmpItem;	 
	}	
	ReturnJSONFromResultArray($returnArray, "", "");
}


//查询操作数值信息
function HttpAction_GetSysLogTotalList()
{
	$msg = "";
	$returnArray = array(); 
	
	$str_sql = "select * from t_log_total";
	$rArray = DBHelper::Query($str_sql, $msg); 
	if($rArray != -1)
	{
		$len = count($rArray);
		for($i = 0; $i < $len; $i++)
		{
			$name = $rArray[$i]["name"];
			$tmpItem[$name] = $rArray[$i]["count"];  
		}
	}
	//WriteLog(json_encode2($tmpItem));
	$total_bar_talking = $tmpItem["total_bar_talking"]; 		//酒吧邂逅总数
	$total_bar_addtime = $tmpItem["total_bar_addtime"]; 		//约会续杯总数

	$total_bar_pk = $tmpItem["total_bar_pk"];  					//插足总数
	$total_bar_pk_success = $tmpItem["total_bar_pk_success"]; 	//插足成功总数
	
	//续杯率 续杯次数/邂逅次数
	if($total_bar_talking <= 0)
		$total_bar_talking = 1;
	$tmpItem["total_bar_addtime_percent"] = GetPercentFormat($total_bar_addtime / $total_bar_talking); 

	//插足成功率
	if($total_bar_pk <= 0)
		$total_bar_pk = 1;
	$tmpItem["total_bar_pk_success_percent"] = GetPercentFormat($total_bar_pk_success / $total_bar_pk);  
	
	$returnArray[] = $tmpItem;
	ReturnJSONFromResultArray($returnArray, "", "");
}

?>
